#!/usr/bin/env python

import sys
import os
import time
import gobject

audio = False;
try:
   # BlendIt uses the audiere library because it seems to be
   # the only library that:
   #    a) is actually cross-platform
   #    b) actually works :P (pymedia, I'm looking at you)
   #    c) works well to  boot 

   import audiere
   audio = True;
except ImportError:
   audio = False;

class Sound:

   dev = None;

   def __init__(self,conf):
      if audio is True:
         self.dev = audiere.open_device();
         self.conf = conf;

   def play(self,notification):
      if self.dev:
         try:
            if not os.path.exists(self.conf[notification]):
               return;
            gobject.timeout_add(50,self.playSound,self.conf[notification]);
         except KeyError:
            pass;

   def playSound(self,file):
      f = self.dev.open_file(file,1);
      f.play();
      while f.playing:
         time.sleep(.01);
      return False;